<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/graphicsview/qgraphicsitem.cpp -->
<head>
  <title>Qt 4.3: QGraphicsItemGroup Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QGraphicsItemGroup Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QGraphicsItemGroup class provides treating a group of items as one. <a href="#details">More...</a></p>
<pre> #include &lt;QGraphicsItemGroup&gt;</pre><p>Inherits <a href="qgraphicsitem.html">QGraphicsItem</a>.</p>
<p>This class was introduced in Qt 4.2.</p>
<ul>
<li><a href="qgraphicsitemgroup-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qgraphicsitemgroup.html#QGraphicsItemGroup">QGraphicsItemGroup</a></b> ( QGraphicsItem * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qgraphicsitemgroup.html#dtor.QGraphicsItemGroup">~QGraphicsItemGroup</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a></b> ( QGraphicsItem * <i>item</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a></b> ( QGraphicsItem * <i>item</i> )</li>
</ul>
<ul>
<li><div class="fn"/>114 public functions inherited from <a href="qgraphicsitem.html#public-functions">QGraphicsItem</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>1 static public member inherited from <a href="qgraphicsitem.html#static-public-members">QGraphicsItem</a></li>
<li><div class="fn"/>23 protected functions inherited from <a href="qgraphicsitem.html#protected-functions">QGraphicsItem</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QGraphicsItemGroup class provides treating a group of items as one.</p>
<p>A QGraphicsItemGroup is a special type of compound item that treats itself and all its children as one item (i.e&#x2e;, all events and geometries for all children are merged together). It's common to use item groups in presentation tools, when the user wants to group several smaller items into one big item in order to simplify moving and copying of items.</p>
<p>If all you want is to store items inside other items, you can use any <a href="qgraphicsitem.html">QGraphicsItem</a> directly by passing a suitable parent to <a href="qgraphicsitem.html#setParentItem">setParentItem</a>().</p>
<p>The <a href="qgraphicsitem.html#boundingRect">boundingRect</a>() function of QGraphicsItemGroup returns the bounding rectangle of all items in the item group. In addition, item groups have <a href="qgraphicsitem.html#handlesChildEvents">handlesChildEvents</a>() enabled by default, so all events sent to a member of the group go to the item group (i.e&#x2e;, selecting one item in a group will select them all).</p>
<p>There are two ways to construct an item group. The easiest and most common approach is to pass a list of items (e.g&#x2e;, all selected items) to <a href="qgraphicsscene.html#createItemGroup">QGraphicsScene::createItemGroup</a>(), which returns a new QGraphicsItemGroup item. The other approach is to manually construct a QGraphicsItemGroup item, add it to the scene calling <a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>(), and then add items to the group manually, one at a time by calling <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>(). To dismantle (&quot;ungroup&quot;) an item group, you can either call <a href="qgraphicsscene.html#destroyItemGroup">QGraphicsScene::destroyItemGroup</a>(), or you can manually remove all items from the group by calling <a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a>().</p>
<pre><span class="comment"> //</span> Group all selected items together
 QGraphicsItemGroup *group = scene-&gt;createItemGroup(scene-&gt;selecteditems());

<span class="comment"> //</span> Destroy the group, and delete the group item
 scene-&gt;destroyItemGroup(group);</pre>
<p>The operation of adding and removing items preserves the items' scene-relative position and transformation, as opposed to calling <a href="qgraphicsitem.html#setParentItem">setParentItem</a>(), where only the child item's parent-relative position and transformation are kept.</p>
<p>The addtoGroup() function reparents the target item to this item group, keeping the item's position and transformation intact relative to the scene. Visually, this means that items added via <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>() will remain completely unchanged as a result of this operation, regardless of the item or the group's current position or transformation; although the item's position and matrix are likely to change.</p>
<p>The <a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a>() function has similar semantics to <a href="qgraphicsitem.html#setParentItem">setParentItem</a>(); it reparents the item to the parent item of the item group. As with <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>(), the item's scene-relative position and transformation remain intact.</p>
<p>See also <a href="qgraphicsitem.html">QGraphicsItem</a> and <a href="graphicsview.html">The Graphics View Framework</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QGraphicsItemGroup"></a>QGraphicsItemGroup::QGraphicsItemGroup ( <a href="qgraphicsitem.html">QGraphicsItem</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a <a href="qgraphicsitemgroup.html">QGraphicsItemGroup</a>. <i>parent</i> is passed to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</p>
<p>See also <a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>().</p>
<h3 class="fn"><a name="dtor.QGraphicsItemGroup"></a>QGraphicsItemGroup::~QGraphicsItemGroup ()</h3>
<p>Destroys the <a href="qgraphicsitemgroup.html">QGraphicsItemGroup</a>.</p>
<h3 class="fn"><a name="addToGroup"></a>void QGraphicsItemGroup::addToGroup ( <a href="qgraphicsitem.html">QGraphicsItem</a> * <i>item</i> )</h3>
<p>Adds the given <i>item</i> to this item group. The item will be reparented to this group, but its position and transformation relative to the scene will stay intact.</p>
<p>See also <a href="qgraphicsitemgroup.html#removeFromGroup">removeFromGroup</a>() and <a href="qgraphicsscene.html#createItemGroup">QGraphicsScene::createItemGroup</a>().</p>
<h3 class="fn"><a name="removeFromGroup"></a>void QGraphicsItemGroup::removeFromGroup ( <a href="qgraphicsitem.html">QGraphicsItem</a> * <i>item</i> )</h3>
<p>Removes the specified <i>item</i> from this group. The item will be reparented to this group's parent item, or to 0 if this group has no parent. Its position and transformation relative to the scene will stay intact.</p>
<p>See also <a href="qgraphicsitemgroup.html#addToGroup">addToGroup</a>() and <a href="qgraphicsscene.html#destroyItemGroup">QGraphicsScene::destroyItemGroup</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
